// 导入路由
import { Router, Route, Redirect, Switch } from 'react-router-dom'

// 导入页面组件
import Login from './pages/Login'
import Layout from './pages/Layout'
import ProfileEdit from './pages/Profile/Edit'
// import PrivateRoute from './components/PrivateRoute'
import PrivateRoute from './components/PrivateRoute'
import history from '@/utils/history'
import Chat from './pages/Profile/Chat'
import Article from './pages/Article'
import Search from './pages/Search'
import SearchResult from './pages/Search/Result'

// 配置路由规则
function App() {
  return (
    <Router history={history}>
      <div className="app">
        <Switch>
          {/* Redirect组件from属性:必须丢在Switch中,才能生效 */}
          {/* <Redirect exact from="/" to="/login"></Redirect> */}
          <Redirect exact from="/" to="login" />
          <Route path="/login" component={Login}></Route>
          <Route path="/home" component={Layout}></Route>
          <Route path="/article/:id" component={Article}></Route>
          <Route exact path="/search" component={Search}></Route>
          <Route exact path="/search/result" component={SearchResult}></Route>
          <PrivateRoute
            path="/profile/edit"
            component={ProfileEdit}
          ></PrivateRoute>
          <PrivateRoute path="/chat" component={Chat}></PrivateRoute>
        </Switch>
      </div>
    </Router>
  )
}

export default App
